home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / GrabAllURLs.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-29  |  6KB  |  157 lines

  1. /*                         GrabAllURLs.rexx
  2.                            v1.3 - 29-Jun-97
  3.  
  4.    This script grabs all URLs from the read messages in the folder and displays 
  5.    them in a requester.  From that requester you can send the URL to your browser.
  6.    Currently supported browsers are AWeb, IBrowse and Voyager.
  7.    
  8.    All adresses which end with a character in variable dup_chars will be 
  9.    duplicated and displayed also without that character.
  10.  
  11.    The script requires rexxreqtools.library and reqtools.library.
  12.    
  13.    Send bug reports, comments and Gillian Anderson pictures to knikulai@utu.fi
  14.  
  15.    If you send a message with subject REQUEST INDEX, you'll get a list
  16.    of my AREXX scripts. REQUEST <filename> will get you the script you
  17.    want.
  18.  
  19. */
  20. options results
  21. call addlib('rexxreqtools.library',0,-30,0)
  22. call addlib('rexxsupport.library',0,-30,0)
  23.  
  24.  screen='YAMscreen'    /* Change these to suit your system */
  25. browser='Work:IBrowse/IBrowse'
  26. hotlist='Work:IBrowse/IBrowse-hotlist.html'
  27. dup_chars='.,!?"*%&)'    /* If one of these ends the URL, it will be duplicated */
  28. wid=70            /* how many characters of the URL is shown? */
  29. maxbut=17        /* How many buttons fit the screen ? */
  30. maxurl=17        /* How many lines of URLs fit the screen ? 
  31.                            This may be different from maxbut, if you wish.*/
  32.       title='GrabAllURLs.rexx by knikulai@utu.fi'
  33.   not_found='Sorry, could not find any URLs!'
  34. found_these='The following URLs were found:'
  35.    desc_txt='Enter description for' || '0a'x
  36. NL='0a'x        /* newline */
  37. uc=0            /* URL-counter */
  38.  
  39. address 'YAM'
  40. GetFolderInfo Max
  41. n=result
  42. do viesti=0 to n-1
  43.     SetMail viesti
  44.     GetMailInfo File
  45.     fname=result
  46.     GetMailInfo Status
  47.     if pos(result,'UN')=0 then do  /* The message isn't new or unread */
  48.        if open(msg,fname,'R') then do
  49.            do until eof(msg) | uc=maxurl 
  50.                rivi=translate(readln(msg),' ','"')
  51.                rivi=rivi || '  '        /* Just making sure there is a space at the end */
  52.                do while uc<maxurl & (pos('GOPHER://',upper(rivi))>0 | pos('FILE://',upper(rivi))>0 | pos('HTTP://',upper(rivi))>0 | pos('FTP://',upper(rivi))>0)
  53.                   /* There might be several URLs on one line */
  54.                   b=pos('HTTP://',upper(rivi))        /* beginning */
  55.                   if b=0 then b=pos('FTP://',upper(rivi))
  56.                   /* Adding other types is easy, just add a line like this: */      
  57.               if b=0 then b=pos('GOPHER://',upper(rivi))
  58.               if b=0 then b=pos('FILE://',upper(rivi))
  59.               e=pos(' ',rivi,b)            /* space ends the URL */
  60.                   if e-pos('//',rivi,b)>2 then do    /* only save if URL has chars in it */
  61.                   call AddURL(substr(rivi,b,e-b))    /* save URL */
  62.                   do while uc<maxurl & pos(right(url.uc,1),dup_chars)>0 
  63.                   /* Add another URL without the last character */
  64.                       spare=left(url.uc,length(url.uc)-1)
  65.                       call AddURL(spare)          
  66.                       end /* do while uc<maxurl & pos */
  67.           end /*if e-pos('//',rivi,b)>2*/
  68.           rivi=right(rivi,length(rivi)-e)
  69.                end /* do while uc<maxurl & (pos('FILE://',upper(rivi))> */
  70.            end /* do until eof(msg) */
  71.            close(msg)
  72.         end /* if open(msg,fname,'R') then do */
  73.     end /* if pos(result,'UN')=0 then do */
  74. end /* do viesti=0 to n-1 */
  75. if uc=0 then
  76.        call rtezrequest(not_found,,title,'rt_pubscrname='screen)
  77. else do
  78.        body=found_these || NL
  79.        buttons=''
  80.        do i=1 to uc
  81.               if i<10 then 
  82.            shortcut='_'
  83.        else
  84.            shortcut=''
  85.            if i<=maxbut then buttons=buttons || shortcut || i || '|'
  86.            body=body || i || ') '
  87.            if length(url.i)<=wid then
  88.            body=body || url.i || NL
  89.        else
  90.            body=body || left(url.i,40) || '...' || right(url.i,wid-43) || NL
  91.            end /* do i=1 to uc */
  92.        buttons=buttons || '_Ok'
  93.        sel=rtezrequest(body,buttons,title,'rtez_defaultresponse=0 rt_pubscrname='screen)
  94.        if sel>0 then do       
  95.        lst=show('P') || '  '
  96.        no_browser=1
  97.        if pos('VOYAGER',lst)>0 then do
  98.           address 'VOYAGER' 'OpenURL '|| url.sel
  99.           no_browser=0
  100.           end
  101.        if pos('MINDWALKER',lst)>0 then do
  102.           address 'MINDWALKER' 'OpenURL '|| url.sel
  103.           no_browser=0
  104.           end
  105.        if pos('IBROWSE',lst)>0 then do
  106.           address 'IBROWSE' 'GotoURL ' || url.sel
  107.           no_browser=0
  108.           end
  109.        if pos('AWEB',lst)>0 then do
  110.         address value substr(lst,pos('AWEB.',lst),6)        
  111.         'Open ' || url.sel
  112.         no_browser=0
  113.         end
  114.        if no_browser then do
  115.         address 'YAM'
  116.                 buts="_Run browser|_Add URL to hotlist|_Exit script"
  117.                 if ~exists(hotlist) then buts="_Run browser|_Exit script"
  118.                 'Request "No browser is currently running!  What do you want to do?" "'buts'"'
  119.                 if result=0 then exit
  120.                 if result=1 then
  121.                         address command 'run >nil:' browser url.sel
  122.                 else do
  123.                         if ~open(6,hotlist,'r') | ~open(7,'t:gu.tmp','w') then do
  124.                                 'Request "Could not write to hotlist" "_Ok"'
  125.                                 exit
  126.                                 end
  127.                         do until upper(line)='<UL>' | eof(6)
  128.                                 line=readln(6)
  129.                                 call writeln(7,line)
  130.                                 end
  131.                         desc=rtgetstring(url.sel,desc_txt || url.sel,title,,'rt_pubscrname='screen)
  132.                         if desc='' then exit
  133.                         call writeln(7,'<LI><A HREF="'url.sel'">'desc'</A>')
  134.                         do until eof(6)
  135.                                 line=readln(6)
  136.                                 if ~eof(6) then call writeln(7,line)
  137.                                 end
  138.                         call close(6)
  139.                         call close(7)
  140.                         address command 'copy' hotlist hotlist || '.old'
  141.                         address command 'copy t:gu.tmp' hotlist
  142.                         address command 'delete t:gu.tmp'
  143.                         end
  144.                 end
  145.        end /* if sel>0 then do */
  146. end /* else */
  147. exit
  148.  
  149. AddURL:
  150.   parse arg u
  151.   do i=1 to uc
  152.       if url.i=u then return
  153.       end
  154.   uc=uc+1
  155.   url.uc=u
  156. return
  157.